package com.example.demo.mapper;

import com.example.demo.model.Hero;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author Hae
 * @Date 2019/9/12 10:40
 * @Version 1.0
 */
@Mapper
public interface HeroMapper {

    @Select("SELECT * FROM `hero` t")
    List<Hero> getAllHeros();

    @Select("SELECT * FROM `hero` t WHERE t.id = #{id}")
    Hero getHeroById(int id);

    @Insert("INSERT INTO hero(name) VALUES(#{name})")
    int addHero(Hero hero);

    @Update("UPDATE hero t SET t.`name` = #{name} WHERE t.id = #{id}")
    int updateHero(Hero hero);

    @Delete("DELETE FROM hero t WHERE t.id = #{id}")
    int deleteHero(int id);

    @Select("SELECT * FROM `hero` t WHERE t.name like concat('%', #{name}, '%')") // concat('%',#{selectword},'%') '%' || #{name} || '%'
    List<Hero> getHeroByName(String name);
}
